


function fanyeTest(page,categoryId,count) {
	page2=page;//改变现实页数
	setCookie2("searchAdmin", searchInfo2);
	jquery.ajax({
		type : 'POST',
		url : '../AdminServlet?method=search&btype=title&page='
			+ page+ "&pageCount=20&sort=desc&sorttype=id&fuzzy=true&name="
			+ categoryId,
		cache : false,
		async : false,
		data : '',
		dataType : 'html',
		success : function(data) {
			setCookie2("pageTotalAdmin",count);
			$("#infos").html(data);					//显示图书列表到#infos
			creatPageBar2();
		},
		error: function() {
			alert("请求失败");
		}
	});
}

var page2 = 1;
var searchInfo2 = "";
//var xmlhttp;
//
//function initAjax() {// 初始化ajax
//	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
//		xmlhttp = new XMLHttpRequest();
//	} else {// code for IE6, IE5
//		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
//	}
//}

//function choose() {
//	initAjax();
//	setCookie2("searchAdmin", searchInfo2);
//	xmlhttp.open("post", "../AdminServlet?method=search&btype=title&page="
//			+ page2 + "&pageCount=20&sort=desc&sorttype=id&fuzzy=true&name="
//			+ searchInfo2, true);
//	xmlhttp.onreadystatechange = searchBook;
//	xmlhttp.send(null);
//}
//function searchBook() {
//	// Ajax引擎状态为成功
//	if (xmlhttp.readyState == 4) {
//		// HTTP协议状态为成功
//		if (xmlhttp.status == 200) {
//			if (xmlhttp.responseText == -1) {
//				setCookie2("pageTotalAdmin", 0);
//			} else if (xmlhttp.responseText >= 0) {
//				setCookie2("pageTotalAdmin", xmlhttp.responseText);
//				window.location.href = "admin-book.jsp?page=" + page2;
//			} else if (xmlhttp.responseText == "true") {
//				window.location.href = "admin-book.jsp?page=" + page2;
//			} else {
//				alert("无法连接服务器");
//			}
//		} else {
//			alert("请求失败，错误码=" + xmlhttp.status);
//		}
//	}
//}
// 获取url地址参数
function GetRequest2() {
	var url = location.search; // 获取url中"?"符后的字串
	var theRequest = new Object();
	if (url.indexOf("?") != -1) {
		var str = url.substr(1);
		strs = str.split("&");
		for (var i = 0; i < strs.length; i++) {
			theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
		}
	}
	return theRequest;
}

/* ========================分页js================================ */
function creatPageBar2() {
	var RJPageBar = document.getElementById('RJ-pagebar');
	var mark = document.getElementById('mark');
	var Request = GetRequest2();
	var page;
	var pageCount = getCookie2("pageTotalAdmin");
	var singleCount = 20;
	if (Request["page"]) {
		page = Request["page"];
	} else {
		page = 1;
	}
	if (pageCount == 0) {
		pageCount = 1;
	}
	if (pageCount < singleCount) {
		singleCount = pageCount;
	}
	RJPageBar.innerHTML = "";
	RJ_Pagebar2({
		id : 'RJ-pagebar', // 容器ID : 必选参数
		CurrentPage : page, // 当前页 ： 可选参数，默认值为1
		SingleCount : singleCount, // 显示数目： 可选参数，只能为奇数，默认值为7，
		PageCount : pageCount, // 必选参数
		callback : function(pagenow, pagecount) {
			mark.innerHTML = '当前页:' + pagenow + ',总共页:' + pagecount;
		}
	})
}
function RJ_Pagebar2(opt) {
	if (!opt.id) {
		return false
	};
	if (!opt.PageCount) {
		return false
	};
	var _obj = document.getElementById(opt.id);
	var _cp = parseInt(opt.CurrentPage) > parseInt(opt.PageCount) ? 1
			: parseInt(opt.CurrentPage) || 1;
	var _sc = parseInt(opt.SingleCount) > parseInt(opt.PageCount) ? 7
			: parseInt(opt.SingleCount) || 7;
	var _pc = parseInt(opt.PageCount);
	if (_sc % 2 == 0) {
		_sc = _sc - 1
	};
	var callback = opt.callback || function() {
	};

	if (_cp != 1) {
		var of = document.createElement('a');
		of.href = "#" + (1);
		of.innerHTML = "首页";
		_obj.appendChild(of);
		var oA = document.createElement('a');
		oA.href = "#" + (_cp - 1);
		oA.innerHTML = "上一页";
		_obj.appendChild(oA);
	} else {
		var of = document.createElement('span');
		of.className = "RU-pagedisabled";
		of.innerHTML = "首页";
		_obj.appendChild(of);
		var oS = document.createElement('span');
		oS.className = "RU-pagedisabled";
		oS.innerHTML = "上一页";
		_obj.appendChild(oS);
	}

	if (_cp <= (_sc - 1) / 2) {
		for (i = 1; i <= _sc; i++) {
			if (i == _cp) {
				var oS = document.createElement('span');
				oS.className = 'RU-pagenow';
				oS.innerHTML = i.toString().length == 1 ? "0" + i : i;
				_obj.appendChild(oS);
			} else {
				var oA = document.createElement('a');
				oA.href = "#" + i;
				oA.innerHTML = i.toString().length == 1 ? "0" + i : i;
				_obj.appendChild(oA);
			}
		}
		var oS = document.createElement('span');
		oS.innerHTML = "…";
		_obj.appendChild(oS);
	} else if (_cp <= _pc && _cp >= _pc - (_sc - 1) / 2) {
		var oS = document.createElement('span');
		oS.innerHTML = "…";
		_obj.appendChild(oS);
		for (i = _pc - _sc + 1; i <= _pc; i++) {
			if (i == _cp) {
				var oS = document.createElement('span');
				oS.className = 'RU-pagenow';
				oS.innerHTML = i.toString().length == 1 ? "0" + i : i;
				_obj.appendChild(oS);
			} else {
				var oA = document.createElement('a');
				oA.href = "#" + i;
				oA.innerHTML = i.toString().length == 1 ? "0" + i : i;
				_obj.appendChild(oA);
			}
		}
	} else {
		var oS = document.createElement('span');
		oS.innerHTML = "…";
		_obj.appendChild(oS);

		for (i = _cp - (_sc - 1) / 2; i < (parseInt(_cp) + parseInt(_sc) - (_sc - 1) / 2); i++) {
			if (i == _cp) {
				var oS = document.createElement('span');
				oS.className = 'RU-pagenow';
				oS.innerHTML = i.toString().length == 1 ? "0" + i : i;
				_obj.appendChild(oS);
			} else {
				var oA = document.createElement('a');
				oA.href = "#" + i;
				oA.innerHTML = i.toString().length == 1 ? "0" + i : i;
				_obj.appendChild(oA);
			}
		}
		var oS = document.createElement('span');
		oS.innerHTML = "…";
		_obj.appendChild(oS);
	}

	if (_cp != _pc) {
		var oA = document.createElement('a');
		oA.href = "#" + (_cp + 1);
		oA.innerHTML = "下一页";
		_obj.appendChild(oA);
		var oe = document.createElement('a');
		oe.href = "#" + (opt.PageCount);
		oe.innerHTML = "末页";
		_obj.appendChild(oe);
	} else {
		var oS = document.createElement('span');
		oS.className = "RU-pagedisabled";
		oS.innerHTML = "下一页";
		_obj.appendChild(oS);
		var of = document.createElement('span');
		of.className = "RU-pagedisabled";
		of.innerHTML = "末页";
		_obj.appendChild(of);
	}

	callback(_cp, _pc);

	var cA = _obj.getElementsByTagName('a');
	for (var i = 0; i < cA.length; i++) {
		cA[i].onclick = function() {
			var pagenum = parseInt(this.getAttribute('href').substring(1));
			_obj.innerHTML = "";
			page2 = pagenum;
			choose();
			return false;
		}
	}
}

// =======================cookie===============================
// 写cookies

function setCookie2(name, value) {
	var Days = 30;
	var exp = new Date();
	exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
	document.cookie = name + "=" + escape(value) + ";expires="
			+ exp.toGMTString();
}

// 读取cookies
function getCookie2(name) {
	var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
	if (arr = document.cookie.match(reg))
		return unescape(arr[2]);
	else
		return null;
}
// 删除cookies
function delCookie2(name) {
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval = getCookie2(name);
	if (cval != null)
		document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}